package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.FileGroup;
import com.ruoyi.system.service.IFileGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 文件组Controller
 *
 * @author cjie
 * @date 2021-06-13
 */
@Api(tags = " 文件组")
@RestController
@RequestMapping("/fileGroup")
public class FileGroupController extends BaseController {
    @Autowired
    private IFileGroupService fileGroupService;

    /**
     * 查询文件组列表
     */
    @ApiOperation(value="查询文件组列表", notes="查询文件组列表")
    @PreAuthorize(hasPermi = "system:fileGroup:list")
    @GetMapping("/list")
    public TableDataInfo list(FileGroup fileGroup) {
        startPage();
        List<FileGroup> list = fileGroupService.selectFileGroupList(fileGroup);
        return getDataTable(list);
    }

    /**
     * 导出文件组列表
     */
    @ApiOperation(value="导出文件组列表", notes="导出文件组列表")
    @PreAuthorize(hasPermi = "system:fileGroup:export")
    @Log(title = "文件组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileGroup fileGroup) throws IOException {
        List<FileGroup> list = fileGroupService.selectFileGroupList(fileGroup);
        ExcelUtil<FileGroup> util = new ExcelUtil<FileGroup>(FileGroup.class);
        util.exportExcel(response, list, "文件组数据");
    }
    /**
     * 获取文件组详细信息
     */
    @ApiOperation(value="获取文件组详细信息", notes="获取文件组详细信息")
    @PreAuthorize(hasPermi = "system:fileGroup:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(fileGroupService.selectFileGroupById(id));
    }

    /**
     * 新增文件组
     */
    @ApiOperation(value="新增文件组", notes="新增文件组")
    @PreAuthorize(hasPermi = "system:fileGroup:add")
    @Log(title = "文件组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileGroup fileGroup) {
        return fileGroupService.insertFileGroup(fileGroup);
    }

    /**
     * 修改文件组
     */
    @ApiOperation(value="修改文件组", notes="修改文件组")
    @PreAuthorize(hasPermi = "system:fileGroup:edit")
    @Log(title = "文件组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileGroup fileGroup) {
        return fileGroupService.updateFileGroup(fileGroup);
    }

    /**
     * 删除文件组
     */
    @ApiOperation(value="删除文件组", notes="删除文件组")
    @ApiImplicitParam(name = "ids", value = "文件组ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "system:fileGroup:remove")
    @Log(title = "文件组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fileGroupService.deleteFileGroupByIds(ids));
    }
}
